#include "Input.h"


Input::Input(byte type, byte key)
{
	_type = type;
	_key = key;
}

void Input::Do() const
{
	if(_type == 0x0)
	{
		if(_key == 0x0 || _key == 0x1)
		{
			_clickMouse();
		}
	}
	else if(_type == 0x1)
	{
		_generateKey();
	}
}

void Input::_generateKey() const
{
  KEYBDINPUT  kb={0};
  tagINPUT  Inputx={0};
  kb.wVk  = _key;  
  Inputx.type  = INPUT_KEYBOARD;
  Inputx.ki  = kb;
  SendInput(1,&Inputx,sizeof(tagINPUT));

  ZeroMemory(&kb,sizeof(KEYBDINPUT));
  ZeroMemory(&Inputx,sizeof(tagINPUT));

  kb.dwFlags  =  KEYEVENTF_KEYUP;
  kb.wVk    =  _key;
  Inputx.type = INPUT_KEYBOARD;
  Inputx.ki  =  kb;
  SendInput(1,&Inputx,sizeof(tagINPUT));
}

void Input::_clickMouse() const
{
  tagINPUT    Inputx={0};
  Inputx.type      = INPUT_MOUSE;
  
  Inputx.mi.dwFlags  = (_key == 0x1) ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN;
  SendInput(1,&Inputx,sizeof(tagINPUT));

  ZeroMemory(&Inputx,sizeof(INPUT));
  Inputx.type      = INPUT_MOUSE;
  Inputx.mi.dwFlags  = (_key == 0x1) ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP;
  SendInput(1,&Inputx,sizeof(tagINPUT));
}

Input::~Input()
{
}
